[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
log10() Calculate Base 10 Logarithm
#include <math.h>
double log10(x);
double x; Floating-point value
log10() returns the base 10 logarithm of 'x'.
Returns: Base 10 logarithm of 'x'. If 'x' is negative,
matherr() is called with a DOMAIN error, a DOMAIN
error message is printed to 'stderr', 'errno'
(defined in <errno.h>) is set to EDOM (defined in
<math.h>), and the value negative HUGE_VAL (defined
in <math.h>) is returned. If 'x' is 0.0, matherr()
is called with a SING error, a SING error message is
printed to 'stderr', 'errno' is set to EDOM, and the
value negative HUGE_VAL is returned.
Notes: You can modify error handling with the matherr()
routine.
-------------------------------- Example ---------------------------------
The following statements calculate the base 10 logarithm of several
values in an array and report any DOMAIN (negative arguments) or SING
(0.0 argument) errors. A matherr() function is used to distinguish
between the two error types, because the same errno value is returned
for both errors:
#include <math.h> /* for log10(), SING, DOMAIN, exception*/
#include <stdio.h> /* for printf() */
/* 0.0 and -1.1e-5 cause errors */
double value[5] = {100.1, 1.0e300, 0.0, 5.1e-99, -1.1e-5};
int merrno; /* holds type of last math error */
int matherr(e)
struct exception *e;
{
merrno = e->type;
return (0);
}
main()
{
double base10_log;
int i;
for (i = 0; i < 5; i++) {
merrno = 0;
base10_log = log10(value[i]);
/* on an error, an error message is also printed to stderr*/
if (merrno == SING)
printf("SING error in log10()\n");
else if (merrno == DOMAIN)
printf("DOMAIN error in log10()\n");
printf("base 10 logarithm of %e = %e\n",
value[i],base10_log);
}
}
See Also:
exp()
log()
matherr()
pow()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson